package org.itboys.mobile.service;

import org.itboys.mobile.common.SundayCommonConstants;
import org.itboys.mobile.entity.mongo.SundayMember;
import org.itboys.mobile.entity.mongo.ZhongBaoChatGroup;
import org.itboys.mobile.entity.mongo.project.ZhongBaoProject;
import org.itboys.mobile.service.mongo.weixin.SundayWeiXinMemberService;
import org.itboys.mobile.service.mongo.weixin.ZhongBaoWeiXinChatGroupService;
import org.itboys.mobile.service.mongo.weixin.ZhongBaoWeiXinMessageService;
import org.itboys.mobile.service.mongo.weixin.ZhongBaoWeiXinProjectService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import sun.security.provider.Sun;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 作者：jiangxiong
 * 日期：2017年5月8日
 * 联系方式 ：empty90911@126.com
 * 描述：众包_微信_首页_service 2017年11月17日 废弃
 */
@Service
public class ZhongBaoWeixinIndexService {
    protected Logger logger = LoggerFactory.getLogger(getClass());
    @Autowired
    private SundayWeiXinMemberService memberService;
    @Autowired
    private ZhongBaoWeiXinProjectService projectService;
    @Autowired
    private ZhongBaoWeiXinMessageService messageService;
    @Autowired
    private ZhongBaoWeiXinChatGroupService chatGroupService;
    /**
     * 获取消息首页需要的未读消息统计信息
     * @param memberId
     * @return 1,项目审核类（含申请和申请结果），2，报名审核类（含申请和申请结果），3，留言类,4合计
     */
    public Map<String,Object> getIndexData(HttpServletRequest request,Long memberId){
        Map<String,Object> result = new HashMap<String,Object>();
        long messages = 0;
        //项目审核类、报名审核类、项目通知类。总数
        Map<String,Object> param = new HashMap<String,Object>();
        param.put("isDeleted", SundayCommonConstants.NO);
        param.put("status",SundayCommonConstants.NO);
        param.put("memberId",memberId);
        param.put("type !=",SundayCommonConstants.zhongbao_message_type_word);
        messages = messageService.count(param);
        //聊天组
        List<ZhongBaoChatGroup> groups =  chatGroupService.getGroup(request,memberId);
        //项目数量
        param.clear();
        param.put("memberId",memberId);
        long projects = projectService.count(param);
        //推荐人数量
        param.clear();
        param.put("isDeleted", SundayCommonConstants.NO);
        param.put("recommenderId",memberId);
        long recommenders =memberService.count(param);

        result.put("messages",messages);
        result.put("groups",groups);
        result.put("projects",projects);
        result.put("recommenders",recommenders);
        return result;
    }

}
